<html>
<head><meta charset="utf-8"><title>Hygiene Frames Information · t-compiler/rust-analyzer · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/index.html">t-compiler/rust-analyzer</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Hygiene.20Frames.20Information.html">Hygiene Frames Information</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="221434456"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Hygiene%20Frames%20Information/near/221434456" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Edwin Cheng <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Hygiene.20Frames.20Information.html#221434456">(Jan 03 2021 at 05:12)</a>:</h4>
<p>In PR <a href="https://github.com/rust-analyzer/rust-analyzer/pull/7133">7133</a>, I introduced <code>HygineneFrames</code> to store the hygiene information for given HirFileId, but turn out it slowing down a lot. This information is needed because hygiene information is per <em>span</em>, the previous implementation only store the single macro information , which is wrong.</p>



<a name="221434778"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Hygiene%20Frames%20Information/near/221434778" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Edwin Cheng <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Hygiene.20Frames.20Information.html#221434778">(Jan 03 2021 at 05:22)</a>:</h4>
<p>Some background information:</p>
<p>For examples, how '$crate' expanded depends on which 'root' crate is located :</p>
<div class="codehilite" data-code-language="Rust"><pre><span></span><code><span class="sd">//! in crate foo</span>
<span class="n">macro_rules</span><span class="w"> </span><span class="n">m</span><span class="o">!</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">   </span><span class="p">()</span><span class="w"> </span><span class="o">=&gt;</span><span class="w"> </span><span class="p">{</span><span class="w"> </span><span class="fm">vec!</span><span class="p">[</span><span class="cp">$crate</span>::<span class="n">local</span><span class="o">!</span><span class="p">()]</span><span class="w"></span>
<span class="p">}</span><span class="w"></span>
</code></pre></div>
<p>The expansion order in here is : <code>foo::m!</code> =&gt; <code>std::vec!</code> =&gt; <code>$crate::local</code>. <br>
Note that <code>$crate</code> should be expanded respect to <code>foo</code> , but not <code>std</code>. But in previous implementation, we only stored <code>std</code> hygiene frame information but not <code>foo</code> one. To fix this problem. We have to have some mechanisms to get the whole expansion chain information on the fly.</p>



<a name="221434926"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Hygiene%20Frames%20Information/near/221434926" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Edwin Cheng <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Hygiene.20Frames.20Information.html#221434926">(Jan 03 2021 at 05:26)</a>:</h4>
<p>Another road-block is <a href="https://github.com/rust-analyzer/rust-analyzer/blob/895d97cfa016ca46c648d250eccb8befa7863502/crates/hir_def/src/path/lower.rs#L25">how lowering path works</a>:</p>
<div class="codehilite" data-code-language="Rust"><pre><span></span><code><span class="sd">/// Converts an `ast::Path` to `Path`. Works with use trees.</span>
<span class="sd">/// It correctly handles `$crate` based path from macro call.</span>
<span class="k">pub</span><span class="p">(</span><span class="k">super</span><span class="p">)</span><span class="w"> </span><span class="k">fn</span> <span class="nf">lower_path</span><span class="p">(</span><span class="k">mut</span><span class="w"> </span><span class="n">path</span>: <span class="nc">ast</span>::<span class="n">Path</span><span class="p">,</span><span class="w"> </span><span class="n">hygiene</span>: <span class="kp">&amp;</span><span class="nc">Hygiene</span><span class="p">)</span><span class="w"> </span>-&gt; <span class="nb">Option</span><span class="o">&lt;</span><span class="n">Path</span><span class="o">&gt;</span><span class="w"></span>
</code></pre></div>
<p>Note that we don't have <code>AstDatabase</code> here so all salsa magic don't work inside <code>lower_path</code>.</p>



<a name="221445224"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Hygiene%20Frames%20Information/near/221445224" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jonas Schievink  [he/him] <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Hygiene.20Frames.20Information.html#221445224">(Jan 03 2021 at 10:47)</a>:</h4>
<p>(going to revert the slow PR for now, to make sure it doesn't end up in the release tomorrow)</p>



<a name="221485480"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Hygiene%20Frames%20Information/near/221485480" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Edwin Cheng <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Hygiene.20Frames.20Information.html#221485480">(Jan 04 2021 at 03:12)</a>:</h4>
<p>I submitted another draft <a href="https://github.com/rust-analyzer/rust-analyzer/pull/7145">#7145</a> to due with some problems.</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>